<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function validate_email(field,alerttxt)
        {
            with (field)
            {
                //value是输入框中value属性。
                apos=value.indexOf("@")
                dotpos=value.lastIndexOf(".")
                if (apos<1||dotpos-apos<2)
                {
                    alert(alerttxt);return false
                }
                else {
                    return true
                }
            }
        }
        function valid(thisform)
        {
            with (thisform)
            {
                //email input框中name属性 ！！！
                if (validate_email(email,"Not a valid e-mail address!")==false)
                {
                    //name=email的input框获得焦点。
                    email.focus();
                    return false
                }
                //username  input框中name属性
                if (validate_email(username,"no username")==false){
                    username.focus();
                    return false
                }
                if (validate_email(password,"no password")==false){
                    password.focus();
                    return false;
                }
            }
        }

    </script>
</head>
<body>
<form action="DOMdemo.html" method="get" onsubmit="return valid(this)">
    email:<input type="email" name="email">
    username:<input type="text" name="username">
    password:<input type="password" name="password">
    <input type="submit" value="submit">
</form>
</body>
</html>